import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

// 隐藏输入法
void hideKeyboard() => FocusScope.of(Get.context!).requestFocus(FocusNode());

// 清除焦点
void cleanFocus() => FocusScope.of(Get.context!).unfocus();

/// 延时执行
void delayed(int milliseconds, Function() callback) {
  Future.delayed(Duration(milliseconds: milliseconds), callback);
}

///千分位分隔符
String? formatPrice(double? price, {int? decimalDigits = 0}) {
  if (price == null) return null;
  return NumberFormat.currency(
          locale: "en_US",
          customPattern: "#,###",
          decimalDigits: decimalDigits)
      .format(price);
}

extension IntExt on int{
  Decimal toD(){
    return Decimal.fromInt(this);
  }
}

extension DoubleExt on double{
  Decimal toD(){
    return Decimal.parse(toString());
  }
}